package com.xjnt.frameworks.plugin.service;

import java.util.Map;

import com.google.common.collect.Maps;
import com.xjnt.frameworks.core.BaseService;

public class ServiceKit {
	/**
	 * 存储系统中注册的服务类
	 */
	private static Map<String, Class<? extends BaseService<?>>> serviceClasses = Maps.newHashMap();
	
	public static Class<? extends BaseService<?>> getService(String name){
		if(serviceClasses.containsKey(name)){
			return serviceClasses.get(name);
		} else {
			throw new NullPointerException("Unregistered service name: " + name);
		}
	}
	
	protected static void addService(String name, Class<? extends BaseService<?>> clazz){
		if(!serviceClasses.containsKey(name)){
			serviceClasses.put(name, clazz);
		}
	}
	
	protected static void clear(){
		serviceClasses.clear();
	}
}
